package com.ly.im.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ly.im.pojo.Friend;
import com.ly.im.pojo.User;
import com.ly.im.repository.FriendRepository;
import com.ly.im.service.FriendService;
import com.ly.im.utils.ResponseUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author LY
 * @create 2024/2/2 14:56
 * @Description 好友
 */
@Service
public class FriendServiceImpl extends ServiceImpl<FriendRepository, Friend> implements FriendService {

    @Override
    public Object list(Long id) {
        List<User> list = baseMapper.list(id);
        return ResponseUtils.ok(list);
    }

    @Override
    public int saveFriend(Friend friend) {
        return baseMapper.insert(friend);
    }

    @Override
    public Object getFriends(User user) {
        List<User> list = baseMapper.getFriends(user.getId());
        return ResponseUtils.ok(list);
    }

    @Override
    public Object agree(Friend friend) {
        saveFriend(friend);
        Friend fr = new Friend();
        fr.setUid(friend.getFid());
        fr.setFid(friend.getUid());
        saveFriend(fr);
        return ResponseUtils.ok();
    }

}
